package com.sctu.EMSApp;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.sctu.fragment.GuideFragment;
import com.sctu.fragment.MyinfoFragment;
import com.sctu.fragment.PlayFragment;
import com.sctu.fragment.ScenicFragment;

/**
 * Created by zhu on 2015/11/3.
 */
public class BaseActivity extends FragmentActivity implements View.OnClickListener {

    protected LinearLayout scenic, play, guide, myinfo;
    protected Fragment guideFragment,scenicFragment,playFragment,myinfoFragment;
    protected TextView buttomScenicText,buttomPlayText,buttomGuideText,buttomMyinfoText;
    protected ImageView buttomScenicImage,buttomPlayImage,buttomGuideImage,buttomMyinfoImage;

    protected void setBottom() {
        scenic = (LinearLayout) findViewById(R.id.buttom_scenic);
        play = (LinearLayout) findViewById(R.id.buttom_play);
        guide = (LinearLayout) findViewById(R.id.buttom_guide);
        myinfo = (LinearLayout) findViewById(R.id.buttom_myinfo);

        buttomScenicText = (TextView) findViewById(R.id.buttom_scenic_text);
        buttomPlayText = (TextView) findViewById(R.id.buttom_play_text);
        buttomGuideText = (TextView) findViewById(R.id.buttom_guide_text);
        buttomMyinfoText = (TextView) findViewById(R.id.buttom_myinfo_text);
        buttomScenicImage = (ImageView) findViewById(R.id.buttom_scenic_image);
        buttomPlayImage = (ImageView) findViewById(R.id.buttom_play_image);
        buttomGuideImage = (ImageView) findViewById(R.id.buttom_guide_image);
        buttomMyinfoImage = (ImageView) findViewById(R.id.buttom_myinfo_image);

        scenic.setOnClickListener(this);
        play.setOnClickListener(this);
        guide.setOnClickListener(this);
        myinfo.setOnClickListener(this);

        setFragment();

    }
    protected void setFragment() {
        guideFragment = new GuideFragment();
        scenicFragment = new ScenicFragment();
        playFragment = new PlayFragment();
        myinfoFragment = new MyinfoFragment();
    }


    @Override
    public void onClick(View v) {
        FragmentTransaction fragmentTransaction =  getSupportFragmentManager().beginTransaction();
        switch (v.getId()) {
            case R.id.buttom_scenic:
                if (!scenicFragment.isAdded()){
                fragmentTransaction.replace(R.id.fragment_contents, scenicFragment);
                fragmentTransaction.commit();
                changeBack(1);
                }
                break;
            case R.id.buttom_play:
                if (!playFragment.isAdded()){
                    fragmentTransaction.replace(R.id.fragment_contents, playFragment);
                    fragmentTransaction.commit();
                    changeBack(2);
                }
                break;
            case R.id.buttom_guide:
                if (!guideFragment.isAdded()){
                fragmentTransaction.replace(R.id.fragment_contents, guideFragment);
                fragmentTransaction.commit();
                changeBack(3);
                }
                break;
            case R.id.buttom_myinfo:
                if (!myinfoFragment.isAdded()){
                fragmentTransaction.replace(R.id.fragment_contents, myinfoFragment);
                fragmentTransaction.commit();
                changeBack(4);
                }
                break;
        }
    }

    protected void changeBack(int flag){
        switch (flag){
            case 1:
                buttomScenicImage.setBackgroundResource(R.drawable.bottom_scenic_tour_on);
                buttomPlayImage.setBackgroundResource(R.drawable.bottom_fun_emei);
                buttomGuideImage.setBackgroundResource(R.drawable.bottom_wisdom_guides);
                buttomMyinfoImage.setBackgroundResource(R.drawable.bottom_myinfo);
//                changeText(buttomScenicText);
                break;

            case 2:
                buttomScenicImage.setBackgroundResource(R.drawable.bottom_scenic_tour);
                buttomPlayImage.setBackgroundResource(R.drawable.bottom_fun_emei_on);
                buttomGuideImage.setBackgroundResource(R.drawable.bottom_wisdom_guides);
                buttomMyinfoImage.setBackgroundResource(R.drawable.bottom_myinfo);
//                changeText(buttomPlayText);
                break;

            case 3:
                buttomScenicImage.setBackgroundResource(R.drawable.bottom_scenic_tour);
                buttomPlayImage.setBackgroundResource(R.drawable.bottom_fun_emei);
                buttomGuideImage.setBackgroundResource(R.drawable.bottom_wisdom_guides_on);
                buttomMyinfoImage.setBackgroundResource(R.drawable.bottom_myinfo);
//                changeText(buttomGuideText);
                break;

            case 4:
                buttomScenicImage.setBackgroundResource(R.drawable.bottom_scenic_tour);
                buttomPlayImage.setBackgroundResource(R.drawable.bottom_fun_emei);
                buttomGuideImage.setBackgroundResource(R.drawable.bottom_wisdom_guides);
                buttomMyinfoImage.setBackgroundResource(R.drawable.bottom_myinfo_on);
//                changeText(buttomMyinfoText);
                break;
        }



    }

    private void changeText(TextView view){

        buttomScenicText.setTextColor(getResources().getColor(R.color.green));
        buttomPlayText.setTextColor(getResources().getColor(R.color.green));
        buttomGuideText.setTextColor(getResources().getColor(R.color.green));
        buttomMyinfoText.setTextColor(getResources().getColor(R.color.green));

        view.setTextColor(getResources().getColor(R.color.white));
    }
}
